#ifndef _LIB_FIXED_
#define _LIB_FIXED_

const int MAX_FIXED_PRECISION = 15;
const int MAX_FIXED_LENGTH    = 28;

typedef long long   fixed_numerator;

int integer(fixed_numerator x);

class fixed
{
private:
public:
    fixed_numerator value;
    unsigned char   precision;
    void            equalize_precision(fixed &);
    class           scale
    {
    public:
        fixed_numerator x[MAX_FIXED_PRECISION + 1];
        scale();
    };
    static scale SCALE;
public:
    fixed(int x, int p)
    {
        value = x; 
        precision = p;
    }
    fixed (const char *);
    fixed        operator [] (int) const;
    fixed        operator =  (fixed);
    fixed        operator =  (int);
    friend fixed operator +  (fixed, fixed);
    friend fixed operator -  (fixed, fixed);
    friend fixed operator *  (fixed, fixed);
    friend fixed operator /  (fixed, fixed);
    friend fixed operator -  (fixed);
    friend fixed operator ++ (fixed);
    friend bool  operator == (fixed, fixed);
    friend bool  operator <  (fixed, fixed);
    friend fixed operator -  (int, fixed);
    friend fixed operator /  (int, fixed);
    friend bool  operator == (int, fixed);
    friend bool  operator <  (int, fixed);
    friend fixed operator +  (fixed, int);
    friend fixed operator -  (fixed, int);
    friend fixed operator *  (fixed, int);
    friend fixed operator /  (fixed, int);
    friend bool  operator == (fixed, int);
    friend bool  operator <  (fixed, int);
    enum { ALIGN=1, COMMAS=2, DECIMAL=4 };
    const char* show(int = COMMAS) const;
    int whole(void) const;
};


typedef class fixed   fixed_t;

bool  operator != (fixed x, fixed y);
bool  operator != (fixed x, int y);
bool  operator != (int x, fixed y);
bool  operator >= (fixed x, fixed y);
bool  operator >= (fixed x, int y);
bool  operator >= (int x, fixed y);
bool  operator >  (fixed x, fixed y);
bool  operator >  (fixed x, int y);
bool  operator >  (int x, fixed y);
bool  operator <= (fixed x, fixed y);
bool  operator <= (fixed x, int y);
bool  operator <= (int x, fixed y);
fixed operator +  (int x, fixed y);
fixed operator *  (int x, fixed y);

#endif

